home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / doc / history.n < prev    next >
Encoding:
Text File  |  1994-12-17  |  6.4 KB  |  169 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" Copyright (c) 1994 Sun Microsystems, Inc.
  4. '\"
  5. '\" See the file "license.terms" for information on usage and redistribution
  6. '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '\" 
  8. '\" @(#) history.n 1.2 94/12/17 16:18:06
  9. '\" 
  10. .so man.macros
  11. .HS history tcl
  12. .BS
  13. '\" Note:  do not modify the .SH NAME line immediately below!
  14. .SH NAME
  15. history \- Manipulate the history list
  16. .SH SYNOPSIS
  17. \fBhistory \fR?\fIoption\fR? ?\fIarg arg ...\fR?
  18. .BE
  19.  
  20. .SH DESCRIPTION
  21. .PP
  22. The \fBhistory\fR command performs one of several operations related to
  23. recently-executed commands recorded in a history list.  Each of
  24. these recorded commands is referred to as an ``event''.  When
  25. specifying an event to the \fBhistory\fR command, the following
  26. forms may be used:
  27. .IP [1]
  28. A number:  if positive, it refers to the event with
  29. that number (all events are numbered starting at 1).  If the number
  30. is negative, it selects an event relative to the current event
  31. (\fB\-1\fR refers to the previous event, \fB\-2\fR to the one before that, and
  32. so on).
  33. .IP [2]
  34. A string:  selects the most recent event that matches the string.
  35. An event is considered to match the string either if the string is
  36. the same as the first characters of the event, or if the string
  37. matches the event in the sense of the \fBstring match\fR command.
  38. .LP
  39. The \fBhistory\fR command can take any of the following forms:
  40. .TP
  41. \fBhistory\fR
  42. Same
  43. as \fBhistory info\fR, described below.
  44. .TP
  45. \fBhistory add\fI command \fR?\fBexec\fR?
  46. Adds the \fIcommand\fR argument to the history list as a new event.  If
  47. \fBexec\fR is specified (or abbreviated) then the command is also
  48. executed and its result is returned.  If \fBexec\fR isn't specified
  49. then an empty string is returned as result.
  50. .TP
  51. \fBhistory change\fI newValue\fR ?\fIevent\fR?
  52. Replaces the value recorded for an event with \fInewValue\fR.  \fIEvent\fR
  53. specifies the event to replace, and
  54. defaults to the \fIcurrent\fR event (not event \fB\-1\fR).  This command
  55. is intended for use in commands that implement new forms of history
  56. substitution and wish to replace the current event (which invokes the
  57. substitution) with the command created through substitution.  The return
  58. value is an empty string.
  59. .TP
  60. \fBhistory event\fR ?\fIevent\fR?
  61. Returns the value of the event given by \fIevent\fR.  \fIEvent\fR
  62. defaults to \fB\-1\fR.  This command causes history revision to occur:
  63. see below for details.
  64. .TP
  65. \fBhistory info \fR?\fIcount\fR?
  66. Returns a formatted string (intended for humans to read) giving
  67. the event number and contents for each of the events in the history
  68. list except the current event.  If \fIcount\fR is specified
  69. then only the most recent \fIcount\fR events are returned.
  70. .TP
  71. \fBhistory keep \fIcount\fR
  72. This command may be used to change the size of the history list to
  73. \fIcount\fR events.  Initially, 20 events are retained in the history
  74. list.  This command returns an empty string.
  75. .TP
  76. \fBhistory nextid\fR
  77. Returns the number of the next event to be recorded
  78. in the history list.  It is useful for things like printing the
  79. event number in command-line prompts.
  80. .TP
  81. \fBhistory redo \fR?\fIevent\fR?
  82. Re-executes the command indicated by \fIevent\fR and return its result.
  83. \fIEvent\fR defaults to \fB\-1\fR.  This command results in history
  84. revision:  see below for details.
  85. .TP
  86. \fBhistory substitute \fIold new \fR?\fIevent\fR?
  87. Retrieves the command given by \fIevent\fR
  88. (\fB\-1\fR by default), replace any occurrences of \fIold\fR by
  89. \fInew\fR in the command (only simple character equality is supported;
  90. no wild cards), execute the resulting command, and return the result
  91. of that execution.  This command results in history
  92. revision:  see below for details.
  93. .TP
  94. \fBhistory words \fIselector\fR ?\fIevent\fR?
  95. Retrieves from the command given by \fIevent\fR (\fB\-1\fR by default)
  96. the words given by \fIselector\fR, and return those words in a string
  97. separated by spaces.  The \fBselector\fR argument has three forms.
  98. If it is a single number then it selects the word given by that
  99. number (\fB0\fR for the command name, \fB1\fR for its first argument,
  100. and so on).  If it consists of two numbers separated by a dash,
  101. then it selects all the arguments between those two.  Otherwise
  102. \fBselector\fR is treated as a pattern; all words matching that
  103. pattern (in the sense of \fBstring match\fR) are returned.  In
  104. the numeric forms \fB$\fR may be used
  105. to select the last word of a command.
  106. For example, suppose the most recent command in the history list is
  107. .RS
  108. .DS
  109. \fBformat  {%s is %d years old} Alice [expr $ageInMonths/12]\fR
  110. .DE
  111. Below are some history commands and the results they would produce:
  112. .DS
  113. .ta 4c
  114. .fi
  115. .UL Command "    "
  116. .UL Result
  117. .nf
  118.  
  119. \fBhistory words $    [expr $ageInMonths/12]\fR
  120. \fBhistory words 1-2    {%s is %d years  old} Alice\fR
  121. \fBhistory words *a*o*    {%s is %d years old} [expr $ageInMonths/12]\fR
  122. .DE
  123. \fBHistory words\fR results in history revision:  see below for details.
  124. .RE
  125. .SH "HISTORY REVISION"
  126. .PP
  127. The history options \fBevent\fR, \fBredo\fR, \fBsubstitute\fR,
  128. and \fBwords\fR result in ``history revision''.
  129. When one of these options is invoked then the current event
  130. is modified to eliminate the history command and replace it with
  131. the result of the history command.
  132. For example, suppose that the most recent command in the history
  133. list is
  134. .DS
  135. \fBset a [expr $b+2]\fR
  136. .DE
  137. and suppose that the next command invoked is one of the ones on
  138. the left side of the table below.  The command actually recorded in
  139. the history event will be the corresponding one on the right side
  140. of the table.
  141. .ne 1.5c
  142. .DS
  143. .ta 4c
  144. .fi
  145. .UL "Command Typed" "    "
  146. .UL "Command Recorded"
  147. .nf
  148.  
  149. \fBhistory redo    set a [expr $b+2]\fR
  150. \fBhistory s a b    set b [expr $b+2]\fR
  151. \fBset c [history w 2]    set c [expr $b+2]\fR
  152. .DE
  153. History revision is needed because event specifiers like \fB\-1\fR
  154. are only valid at a particular time:  once more events have been
  155. added to the history list a different event specifier would be
  156. needed.
  157. History revision occurs even when \fBhistory\fR is invoked
  158. indirectly from the current event (e.g. a user types a command
  159. that invokes a Tcl procedure that invokes \fBhistory\fR):  the
  160. top-level command whose execution eventually resulted in a
  161. \fBhistory\fR command is replaced.
  162. If you wish to invoke commands like \fBhistory words\fR without
  163. history revision, you can use \fBhistory event\fR to save the
  164. current history event and then use \fBhistory change\fR to
  165. restore it later.
  166.  
  167. .SH KEYWORDS
  168. event, history, record, revision
  169.